package org.rc.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.rc.dto.ConversationTextPageDto;
import org.rc.entity.ConversationText;
import org.rc.mapper.ConversationTextMapper;
import org.rc.service.ConversationTextService;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ConversationTextServiceImpl extends ServiceImpl<ConversationTextMapper, ConversationText> implements ConversationTextService {

    @Override
    public void addRecord(ConversationText conversationText) {
        this.save(conversationText);
    }

    @Override
    public List<ConversationText> getTextByConversationId(Long conversationId) {
        QueryWrapper<ConversationText> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("conversation_id",conversationId).orderByAsc("id");
        return list(queryWrapper);
    }

    @Override
    public void deleteByRecordId(Long id) {
        QueryWrapper<ConversationText> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("conversation_id",id);
        this.remove(queryWrapper);
    }

    @Override
    public void deleteByRecordIds(List<Long> ids) {
        QueryWrapper<ConversationText> queryWrapper = new QueryWrapper<>();
        queryWrapper.in("conversation_id",ids);
        this.remove(queryWrapper);
    }

    @Override
    public Page<ConversationText> getRolePage(ConversationTextPageDto conversationTextPageDto) {
        Page<ConversationText> page = new Page<>(conversationTextPageDto.getPageNo(),conversationTextPageDto.getPageSize());
        QueryWrapper<ConversationText> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("conversation_id",conversationTextPageDto.getId()).orderByAsc("id");
        return this.baseMapper.selectPage(page,queryWrapper);
    }
}
